using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections.Generic;
using System.IO;

using CE.User;
using CE.Global;
using CE.Database;
using CE.CarInsurance;

public partial class carinsurance_QuoteDownload : System.Web.UI.Page
{
    private DateTime dateTimeNow = CE.Global.General.GetUTCDateTime();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/SiteUserSecureLogin.aspx");
        }
        if (!IsPostBack)
        {
            if (Request.QueryString["carid"] != null && Request.QueryString["userid"] != null)
            {
                Int64 CECarId = Convert.ToInt64(Request.QueryString["carid"].ToString());
                Int64 UserId = Convert.ToInt64(Request.QueryString["userid"].ToString());
                GenerateQuote(CECarId, UserId);
            }
        }
    }

    protected void GenerateQuote(Int64 CECarId, Int64 UserId)
    {
        Label lblContent = new Label();
        string _fileName = "Quote_" + CECarId.ToString();

        StringBuilder strText = new StringBuilder("");
        strText.Append("<table><tr><td colspan='4'><h3>Car Insurance : Quote Request</h3></td></tr></table>");

        #region Variable Declaration

        string _html, _name, _gender, _nric, _dob, _dd, _mm, _yy, _occupation, _jobnature, _maritalstatus, _yearsofdriving, _manufactureyear, _registeryear;
        string _carmodel, _offpeek, _ncdpercent, _applicablencd, _offancedriving, _additionaldriver, _commencementdate, _email, _mobile, _vehicleno, _inscomp;
        string _drname1, _drage1, _drgender1, _drmarital1, _drocc1, _drexp1, _drjobnature1, _drname2, _drage2, _drgender2, _drmarital2, _drocc2, _drexp2, _drjobnature2;
        string _drname3, _drage3, _drgender3, _drmarital3, _drocc3, _drexp3, _drjobnature3, _drname4, _drage4, _drgender4, _drmarital4, _drocc4, _drexp4, _drjobnature4;
        string _drname5, _drage5, _drgender5, _drmarital5, _drocc5, _drexp5, _drjobnature5, _drcount, _drDOB1, _drDOB2, _drDOB3, _drDOB4, _drDOB5, _indd, _inmm, _inyy;
        string _claimstatus, _claim1ststat, _claim1stend, _claimcount1, claimamt1, _claim2ndstat, _claim2ndend, claimamt2, _claim3rdstat, _claim3rdend, claimamt3;
        string _insdate;
        DateTime _ddob, _indate;
        DateTime _drddob1 = dateTimeNow;
        DateTime _drddob2 = dateTimeNow;
        DateTime _drddob3 = dateTimeNow;
        DateTime _drddob4 = dateTimeNow;
        DateTime _drddob5 = dateTimeNow;

        _html = ""; _name = ""; _gender = ""; _nric = ""; _dob = ""; _dd = ""; _mm = ""; _yy = ""; _occupation = ""; _jobnature = ""; _maritalstatus = "";
        _yearsofdriving = ""; _manufactureyear = ""; _registeryear = ""; _carmodel = ""; _offpeek = ""; _ncdpercent = ""; _applicablencd = "";
        _offancedriving = ""; _additionaldriver = ""; _commencementdate = ""; _email = ""; _mobile = ""; _vehicleno = ""; _inscomp = "";
        _drname1 = ""; _drage1 = ""; _drgender1 = ""; _drmarital1 = ""; _drocc1 = ""; _drexp1 = ""; _drjobnature1 = "";
        _drname2 = ""; _drage2 = ""; _drgender2 = ""; _drmarital2 = ""; _drocc2 = ""; _drexp2 = ""; _drjobnature2 = "";
        _drname3 = ""; _drage3 = ""; _drgender3 = ""; _drmarital3 = ""; _drocc3 = ""; _drexp3 = ""; _drjobnature3 = "";
        _drname4 = ""; _drage4 = ""; _drgender4 = ""; _drmarital4 = ""; _drocc4 = ""; _drexp4 = ""; _drjobnature4 = "";
        _drname5 = ""; _drage5 = ""; _drgender5 = ""; _drmarital5 = ""; _drocc5 = ""; _drexp5 = ""; _drjobnature5 = ""; _drcount = "0";
        _drDOB1 = ""; _drDOB2 = ""; _drDOB3 = ""; _drDOB4 = ""; _drDOB5 = ""; _indd = ""; _inmm = ""; _inyy = "";
        _claimstatus = ""; _claim1ststat = ""; _claim1stend = ""; _claimcount1 = ""; claimamt1 = ""; _claim2ndstat = ""; _claim2ndend = "";
        claimamt2 = ""; _claim3rdstat = ""; _claim3rdend = ""; claimamt3 = "";
        #endregion

        DataSet _dsNomatchFound = new DataSet();
        BrokerPremiumDB _brokerpremiumdb = new BrokerPremiumDB();
        _dsNomatchFound = _brokerpremiumdb.GetCINomatchFoundQuotes(CECarId, UserId, "CI");
        if (_dsNomatchFound.Tables[0].Rows.Count > 0)
        {
            #region variables
            _name = _dsNomatchFound.Tables[0].Rows[0]["Name"].ToString();
            _nric = _dsNomatchFound.Tables[0].Rows[0]["NRIC"].ToString();
            _manufactureyear = _dsNomatchFound.Tables[0].Rows[0]["ManufactYear"].ToString();
            _registeryear = _dsNomatchFound.Tables[0].Rows[0]["RegYear"].ToString();
            _carmodel = _dsNomatchFound.Tables[0].Rows[0]["MakeModelDesc"].ToString();
            _ddob = Convert.ToDateTime(_dsNomatchFound.Tables[0].Rows[0]["DOB"].ToString());
            _dd = _ddob.Day.ToString("00");
            _mm = _ddob.Month.ToString("00");
            _yy = _ddob.Year.ToString();
            _dob = _dd + "/" + _mm + "/" + _yy;
            //_dob = _dsNomatchFound.Tables[0].Rows[0]["DOB"].ToString();
            _maritalstatus = _dsNomatchFound.Tables[0].Rows[0]["Marital"].ToString();
            _gender = _dsNomatchFound.Tables[0].Rows[0]["Gender"].ToString();
            _jobnature = _dsNomatchFound.Tables[0].Rows[0]["JobNature"].ToString();
            _email = _dsNomatchFound.Tables[0].Rows[0]["Email"].ToString();
            _yearsofdriving = _dsNomatchFound.Tables[0].Rows[0]["YearDriveSg"].ToString();
            _occupation = _dsNomatchFound.Tables[0].Rows[0]["Description"].ToString();
            _mobile = _dsNomatchFound.Tables[0].Rows[0]["Mobile"].ToString();
            if (_dsNomatchFound.Tables[0].Rows[0]["IsClaimLastThreeYear"].ToString() == "0")
            {
                _claimstatus = "No";
            }
            else
            {
                _claimstatus = "Yes";
            }
            _ncdpercent = _dsNomatchFound.Tables[0].Rows[0]["NCDPercent"].ToString();
            if (_ncdpercent.ToString() == "-1")
            {
                _ncdpercent = "No NCD(First Policy)";
            }
            else
            {
                _ncdpercent += "%";
            }
            _applicablencd = _dsNomatchFound.Tables[0].Rows[0]["ApplicableNCD"].ToString();
            _additionaldriver = _dsNomatchFound.Tables[0].Rows[0]["AddDriver"].ToString();
            _offpeek = _dsNomatchFound.Tables[0].Rows[0]["Offbeak"].ToString();
            _offancedriving = _dsNomatchFound.Tables[0].Rows[0]["IsOffDriveCom"].ToString();
            _drcount = _dsNomatchFound.Tables[0].Rows[0]["NoOfDriver"].ToString();
            if (_dsNomatchFound.Tables[1].Rows.Count > 0)
            {
                _claimstatus = "Yes";
                _claim1ststat = _dsNomatchFound.Tables[1].Rows[0]["Claim1stStartDate"].ToString();
                _claim1stend = _dsNomatchFound.Tables[1].Rows[0]["Claim1stEndDate"].ToString();
                claimamt1 = _dsNomatchFound.Tables[1].Rows[0]["NOCLast1Value"].ToString();
                _claimcount1 = _dsNomatchFound.Tables[1].Rows[0]["NOCLast1"].ToString();

                _claim2ndstat = _dsNomatchFound.Tables[1].Rows[0]["Claim2ndStartDate"].ToString();
                _claim2ndend = _dsNomatchFound.Tables[1].Rows[0]["Claim2ndEndDate"].ToString();
                claimamt2 = _dsNomatchFound.Tables[1].Rows[0]["NOCLast2Value"].ToString();

                _claim3rdstat = _dsNomatchFound.Tables[1].Rows[0]["Claim3rdStartDate"].ToString();
                _claim3rdend = _dsNomatchFound.Tables[1].Rows[0]["Claim3rdEndDate"].ToString();
                claimamt3 = _dsNomatchFound.Tables[1].Rows[0]["NOCLast3Value"].ToString();
            }
            else
            {
                _claim1ststat = "";
                _claim1stend = "";
                claimamt1 = "";
                _claimcount1 = "0";

                _claim2ndstat = "";
                _claim2ndend = "";
                claimamt2 = "";

                _claim3rdstat = "";
                _claim3rdend = "";
                claimamt3 = "";
                _claimstatus = "No";
            }


            _vehicleno = _dsNomatchFound.Tables[0].Rows[0]["VehicleNumber"].ToString();
            _indate = Convert.ToDateTime(_dsNomatchFound.Tables[0].Rows[0]["CoverageCommenceDate"].ToString());
            _indd = _indate.Day.ToString("00");
            _inmm = _indate.Month.ToString("00");
            _inyy = _indate.Year.ToString();
            _insdate = _indd + "/" + _inmm + "/" + _inyy;
            if (_dsNomatchFound.Tables[2].Rows.Count > 0)
            {
                _inscomp = _dsNomatchFound.Tables[2].Rows[0]["InsCompanyName"].ToString();
            }
            if (_dsNomatchFound.Tables[3].Rows.Count > 0)
            {
                if (Convert.ToInt16(_drcount) > 0)
                {
                    _drage1 = _dsNomatchFound.Tables[3].Rows[0]["Age"].ToString();
                    _drgender1 = _dsNomatchFound.Tables[3].Rows[0]["Gender"].ToString();
                    _drmarital1 = _dsNomatchFound.Tables[3].Rows[0]["Marital"].ToString();
                    _drocc1 = _dsNomatchFound.Tables[3].Rows[0]["Description"].ToString();
                    _drexp1 = _dsNomatchFound.Tables[3].Rows[0]["YearOfDrivingInSg"].ToString();
                    _drDOB1 = _dsNomatchFound.Tables[3].Rows[0]["DOB"].ToString();
                    //_drddob1 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[0]["DOB"].ToString());
                    _drjobnature1 = _dsNomatchFound.Tables[3].Rows[0]["JobNature"].ToString();
                }
                if (Convert.ToInt16(_drcount) > 1)
                {
                    _drage2 = _dsNomatchFound.Tables[3].Rows[1]["Age"].ToString();
                    _drgender2 = _dsNomatchFound.Tables[3].Rows[1]["Gender"].ToString();
                    _drmarital2 = _dsNomatchFound.Tables[3].Rows[1]["Marital"].ToString();
                    _drocc2 = _dsNomatchFound.Tables[3].Rows[1]["Description"].ToString();
                    _drexp2 = _dsNomatchFound.Tables[3].Rows[1]["YearOfDrivingInSg"].ToString();
                    _drDOB2 = _dsNomatchFound.Tables[3].Rows[1]["DOB"].ToString();
                    //_drddob2 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[1]["DOB"].ToString());
                    _drjobnature2 = _dsNomatchFound.Tables[3].Rows[1]["JobNature"].ToString();
                }
                if (Convert.ToInt16(_drcount) > 2)
                {
                    _drage3 = _dsNomatchFound.Tables[3].Rows[2]["Age"].ToString();
                    _drgender3 = _dsNomatchFound.Tables[3].Rows[2]["Gender"].ToString();
                    _drmarital3 = _dsNomatchFound.Tables[3].Rows[2]["Marital"].ToString();
                    _drocc3 = _dsNomatchFound.Tables[3].Rows[2]["Description"].ToString();
                    _drexp3 = _dsNomatchFound.Tables[3].Rows[2]["YearOfDrivingInSg"].ToString();
                    _drDOB3 = _dsNomatchFound.Tables[3].Rows[2]["DOB"].ToString();
                    //_drddob3 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[2]["DOB"].ToString());
                    _drjobnature3 = _dsNomatchFound.Tables[3].Rows[2]["JobNature"].ToString();
                }
                if (Convert.ToInt16(_drcount) > 3)
                {
                    _drage4 = _dsNomatchFound.Tables[3].Rows[3]["Age"].ToString();
                    _drgender4 = _dsNomatchFound.Tables[3].Rows[3]["Gender"].ToString();
                    _drmarital4 = _dsNomatchFound.Tables[3].Rows[3]["Marital"].ToString();
                    _drocc4 = _dsNomatchFound.Tables[3].Rows[3]["Description"].ToString();
                    _drexp4 = _dsNomatchFound.Tables[3].Rows[3]["YearOfDrivingInSg"].ToString();
                    _drDOB4 = _dsNomatchFound.Tables[3].Rows[3]["DOB"].ToString();
                    //_drddob4 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[3]["DOB"].ToString());
                    _drjobnature4 = _dsNomatchFound.Tables[3].Rows[3]["JobNature"].ToString();
                }
                if (Convert.ToInt16(_drcount) > 4)
                {
                    _drage5 = _dsNomatchFound.Tables[3].Rows[4]["Age"].ToString();
                    _drgender5 = _dsNomatchFound.Tables[3].Rows[4]["Gender"].ToString();
                    _drmarital5 = _dsNomatchFound.Tables[3].Rows[4]["Marital"].ToString();
                    _drocc5 = _dsNomatchFound.Tables[3].Rows[4]["Description"].ToString();
                    _drexp5 = _dsNomatchFound.Tables[3].Rows[4]["YearOfDrivingInSg"].ToString();
                    _drDOB5 = _dsNomatchFound.Tables[3].Rows[4]["DOB"].ToString();
                    //_drddob5 = Convert.ToDateTime(_dsNomatchFound.Tables[3].Rows[4]["DOB"].ToString());
                    _drjobnature5 = _dsNomatchFound.Tables[3].Rows[4]["JobNature"].ToString();
                }
            }

            #endregion

            #region Html
            _html = "<table><tr><td colspan='4'> </td></tr></table>";

            _html += "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>"
                     + "<tr>"
                     + "<td width='50%'>" //Start 1
                     + "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Name</td>"
                     + "<td width='50%' align='left'>" + _name.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Marital Status</td>"
                     + "<td width='50%' align='left'>" + _maritalstatus.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Occupation / Business</td>"
                     + "<td width='50%' align='left'>" + _occupation.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Mobile No</td>"
                     + "<td width='50%' align='left'>" + _mobile.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>NRIC</td>"
                     + "<td width='50%' align='left'>" + _nric.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Car MakeModel</td>"
                     + "<td width='50%' align='left'>" + _carmodel.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Car Manufacture Year</td>"
                     + "<td width='50%' align='left'>" + _manufactureyear.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Existing NCD</td>"
                     + "<td width='50%' align='left'>" + _ncdpercent.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Off Peak</td>"
                     + "<td width='50%' align='left'>" + _offpeek.ToString() + "</td>"
                     + "</tr>"

                     + "</table>"
                     + "</td>" //End 1

                     + "<td width='50%'>" //Start 2
                     + "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Date of Birth</td>"
                     + "<td width='50%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _dob.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Gender</td>"
                     + "<td width='50%' align='left'>" + _gender.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Email</td>"
                     + "<td width='50%' align='left'>" + _email.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Driving Experience</td>"
                     + "<td width='50%' align='left'>" + _yearsofdriving.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Commencement Date</td>"
                     + "<td width='50%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _insdate.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Vehicle No</td>"
                     + "<td width='50%' align='left'>" + _vehicleno.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Register Year</td>"
                     + "<td width='50%' align='left'>" + _registeryear.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>NCD on next renewal (%)</td>"
                     + "<td width='50%' align='left'>" + _applicablencd.ToString() + "</td>"
                     + "</tr>"

                     + "<tr>"
                     + "<td width='50%' align='left'>Offence-Free Driving</td>"
                     + "<td width='50%' align='left'>" + _offancedriving.ToString() + "</td>"
                     + "</tr>"

                     + "</table>"
                     + "</td>" //End 2
                     + "</tr>";

            _html += "</table>";

            _html += "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>";
            _html += "<tr><td colspan='4' align='left'><b>Current Insurer : </b>" + _inscomp.ToString() + "</td></tr>";
            _html += "</table>";

            _html += "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>";

            _html += "<tr><td colspan='4' align='left'><b>Any Claims in the Last 3 Years? : </b>" + _claimstatus.ToString() + "</td></tr>";
            if (_claimstatus == "Yes")
            {
                if (claimamt1.ToString() != "0")
                {
                    _html += "<tr><td style='width:25%' align='left'>Claim Date</td>"
                    + "<td style='width:25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'> " + _claim1ststat.ToString() + " to " + _claim1stend.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'> Claim Amount</td>"
                    + "<td style='width: 25%' align='left'>" + claimamt1.ToString() + "</td></tr>";
                }
                if (claimamt2.ToString() != "0")
                {
                    _html += "<tr><td style='width:25%' align='left'>Claim Date</td>"
                    + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claim2ndstat.ToString() + " to " + _claim2ndend.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'> Claim Amount</td>"
                    + "<td style='width: 25%' align='left'>" + claimamt2.ToString() + "</td></tr>";
                }
                if (claimamt3.ToString() != "0")
                {
                    _html += "<tr><td style='width:25%' align='left'>Claim Date</td>"
                    + "<td style='width: 25%; mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _claim3rdstat.ToString() + " to " + _claim3rdend.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'> Claim Amount</td>"
                    + "<td style='width: 25%' align='left'>" + claimamt3.ToString() + "</td></tr>";
                }
            }

            _html += "</table>";

            _html += "<table style='width: 100%; background-color: white;' cellpadding='0' cellspacing='0' border='1'>";
            _html += "<tr><td colspan='4' align='left'><b>Additional drivers : </b>" + _additionaldriver.ToString() + "</td></tr>";
            if (_additionaldriver == "Yes")
            {
                if (Convert.ToInt16(_drcount) > 0)
                {
                    _html += "<tr><td colspan='4' align='left'>Driver 1</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB1.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp1.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender1.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital1.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc1.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature1.ToString() + "</td></tr>";
                }
                if (Convert.ToInt16(_drcount) > 1)
                {
                    _html += "<tr><td colspan='4' align='left'>Driver 2</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB2.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp2.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender2.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital2.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc2.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature2.ToString() + "</td></tr>";
                }
                if (Convert.ToInt16(_drcount) > 2)
                {
                    _html += "<tr><td colspan='4' align='left'>Driver 3</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB3.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp3.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender3.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital3.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc3.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature3.ToString() + "</td></tr>";
                }
                if (Convert.ToInt16(_drcount) > 3)
                {
                    _html += "<tr><td colspan='4' align='left'>Driver 4</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB4 + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp4.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender4.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital4.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc4.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature4.ToString() + "</td></tr>";
                }
                if (Convert.ToInt16(_drcount) > 4)
                {
                    _html += "<tr><td colspan='4' align='left'>Driver 5</td></tr>"
                    + "<tr><td style='width:25%' align='left'>Driver DOB</td>"
                    + "<td style='width: 25%' style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + _drDOB5 + "</td>"
                    + "<td style='width: 25%' align='left'>Driving Experience</td>"
                    + "<td style='width: 25%' align='left'>" + _drexp5.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Gender</td>"
                    + "<td style='width: 25%' align='left'>" + _drgender5.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Marital Status</td>"
                    + "<td style='width: 25%' align='left'>" + _drmarital5.ToString() + "</td></tr>"

                    + "<tr><td style='width:25%' align='left'>Occupation</td>"
                    + "<td style='width: 25%' align='left'>" + _drocc5.ToString() + "</td>"
                    + "<td style='width: 25%' align='left'>Job Nature</td>"
                    + "<td style='width: 25%' align='left'>" + _drjobnature5.ToString() + "</td></tr>";
                }
            }
            _html += "</table>";
            _html += "</table>";
            #endregion

            string _HeaderText = "<h1>Car Insurance : Quote Request</h1>";
            lblQuoteHtml.Text = _html;
            ExportHtml(_fileName, lblQuoteHtml, _HeaderText);


        }

    }

    public void ExportHtml(string fileName, Label lblPremiumHtml, string headerText)
    {
        string attachment = "attachment; filename=" + fileName + ".htm";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "text/HTML";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        HtmlForm frm = new HtmlForm();
        frm.InnerHtml = headerText;
        lblPremiumHtml.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(lblPremiumHtml);
        frm.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();

        
    }

}
